package org.bleep.input;

import org.lwjgl.input.Keyboard;

public class ToggleButton extends Button
{
	private boolean lastKeyState;
	private boolean buttonState;
	
	public ToggleButton(String name, int keyCode)
	{
		super(name, keyCode);
		lastKeyState = false;
		buttonState = false;
	}
	
	private void checkState()
	{
		boolean currentKeyState = Keyboard.isKeyDown(keyCode);
		if (currentKeyState && !lastKeyState)
		{
			buttonState = !buttonState;
		}
		lastKeyState = currentKeyState;
	}
	
	public boolean isActive()
	{
		checkState();
		return buttonState;
	}
}